package com.akuhome.resource.controller;

import com.akuhome.resource.DO.message.MessageConfig;
import com.akuhome.resource.DO.message.MessageTemplate;
import com.akuhome.resource.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    MessageService messageService;

    @GetMapping("/template")
    public Object findAllMessageTemplate(){
        return messageService.findAllMessageTemplate();
    }

    @GetMapping("/template/{messageTemplateId}")
    public Object findMessageTemplateById(@PathVariable Integer messageTemplateId){
        return messageService.findMessageTemplateById(messageTemplateId);
    }

    @PostMapping("/template")
    public Object insertMessageTemplate(@Validated @RequestBody MessageTemplate messageTemplate, BindingResult bindingResult){
        return messageService.insertMessageTemplate(messageTemplate);
    }

    @PutMapping("/template")
    public Object updateMessageTemplate(@Validated @RequestBody MessageTemplate messageTemplate, BindingResult bindingResult){
        return messageService.updateMessageTemplate(messageTemplate);
    }

    @DeleteMapping("/template/{messageTemplateId}")
    public Object deleteMessageTemplate(@PathVariable Integer messageTemplateId){
        return messageService.deleteMessageTemplateById(messageTemplateId);
    }

    @GetMapping("/config")
    public Object findAllMessageConfig(){
        return messageService.findAllMessageConfig();
    }

    @GetMapping("/config/{messageConfigId}")
    public Object findMessageConfigFormById(@PathVariable Integer messageConfigId){
        return messageService.findMessageConfigById(messageConfigId);
    }

    @PostMapping("/config/{messageConfigId}")
    public Object enableMessageConfig(@PathVariable Integer messageConfigId){
        messageService.updateMessageConfigEnableById(messageConfigId,true);
        return null;
    }
    @PutMapping("/config")
    public Object updateMessageFormConfig(@Validated @RequestBody MessageConfig config, BindingResult bindingResult){
        messageService.updateMessageConfig(config);
        return null;
    }

    @DeleteMapping("/config/{messageConfigId}")
    public Object disableMessageConfig(@PathVariable Integer messageConfigId){
        messageService.updateMessageConfigEnableById(messageConfigId,false);
        return null;
    }

    @GetMapping("/record")
    public Object findAllMessageRecord(){
        return messageService.findAllMessageRecord();
    }

    @GetMapping("/record/{id}")
    public Object findMessageRecordById(@PathVariable Integer id){
        return messageService.findMessageRecordById(id);
    }

    @GetMapping("/type")
    public Object findAllMessageType(){
        return messageService.findAllMessageType();
    }

}
